
<%- include header %>


<!-- 主题内容start -->
<table class="table table-bordered table-striped table-condensed table-hover">
    <tr>
        <th class="span3" colspan="10"><h4 style="text-align: center">帖子(帖子总数：<%- count %>条|当前页：<%- page.num %>/<%- page.pageCount %>)</h4></th>
    </tr>
    <tr>
        <th>主题</th>
        <th>创建时间</th>
        <th>回复数</th>
        <th>点击数</th>
        <th>所属分类</th>
        <th>发帖人用户名</th>
        <th>发帖人昵称</th>
        <th>当前状态</th>
        <th>操作</th>
    </tr>
    <% datas.forEach(function(data,index){ %>
    <tr>
        <td>
            <%- data.theme %>
        </td>
        <td>
            <% Date.prototype.format = function (fmt) { //author: meizz
                var o = {
                    "M+": this.getMonth() + 1, //月份
                    "d+": this.getDate(), //日
                    "h+": this.getHours(), //小时
                    "m+": this.getMinutes(), //分
                    "s+": this.getSeconds(), //秒
                    "q+": Math.floor((this.getMonth() + 3) / 3), //季度
                    "S": this.getMilliseconds() //毫秒
                };
                if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
                for (var k in o)
                    if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
                return fmt;

            }%>
            <%- data.postDate.format('yyyy-MM-dd') %>
        </td>
        <td>
            <%- data.replyTotal %>
        </td>
        <td>
            <%- data.hitTotal %>
        </td>
        <td>
            <%- data.bbsPlate.platename %>
        </td>
        <td>
            <%- data.publishUser.username %>
        </td>
        <td>
            <%- data.publishUser.nickname %>
        </td>
        <td>
            <%- data.state %>
        </td>
        <td>
            <!--<a class="btn btn-danger btn-small" onclick="updateState('<%- data._id %>',1)">置顶</a>-->
            <a class="btn btn-info btn-small" onclick="updateState('<%- data._id %>',2)">水贴</a>
            <a class="btn btn-success btn-small" onclick="updateState('<%- data._id %>',0)">恢复</a>
        </td>
    </tr>
    <% }) %>
</table>
<div class="span12">
    <div id="page1"></div>
</div>
<!-- 主题内容end -->
<%- include footer %>
<script>
    function updateState(id,state){
        var prompt=confirm("你确定执行操作码？？");

        if(prompt){

            window.location.href="/manager/updatePostState?id="+id+"&state="+state;
        }
    }
    $(function(){
        //获得浏览器参数

        $.extend({
            getUrlVars: function(){
                var vars = [];
                var hash;
                var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
                console.log(hashes);
                for(var i = 0; i < hashes.length; i++){
                    hash = hashes[i].split('=');
                    vars.push(hash[0]);
                    vars[hash[0]] = hash[1];
                }
                return vars;
            },
            getUrlVar: function(name){
                return $.getUrlVars()[name];
            }
        });

        //封装浏览器参数
        var composeUrlParams=function(){
            var param='';
            $.each($.getUrlVars(), function(i, item) {
                if(item!='num'){
                    var val=$.getUrlVar(item);
                    if(val) param += "&" + item+"="+val;
                }
            });
            return param;
        }
        var options = {
            currentPage:<%- page.num %>,                //当前页，css样式同其他页不同
            totalPages:<%- page.pageCount %>,           //总页数
            numberOfPages:5,                            //导航最多显示页数
            pageUrl: function(type, page, current) {    //页面跳转
                if(page!=<%- page.num %>){
                    return "/manager/postList?num="+ page+composeUrlParams();
                }

            }
        }
        $('#page1').bootstrapPaginator(options);
    })
</script>



